package de.jmda.core.util;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import de.jmda.core.util.StringUtil;


public class JUTStringUtil
{
	@Test
	public void testAllTrimChars()
	{
		String input = "aaaxxxaaa";
		String charsToTrim = "a";
		String expectedOutput = "xxx";
		assertEquals(expectedOutput, StringUtil.allTrimChars(input, charsToTrim));

		input = "aaaxxxbbbxxxaaa";
		charsToTrim = "xa";
		expectedOutput = "bbb";
		assertEquals(expectedOutput, StringUtil.allTrimChars(input, charsToTrim));

		input = "aaaxxxaaa";
		charsToTrim = "x";
		expectedOutput = "aaaxxxaaa";
		assertEquals(expectedOutput, StringUtil.allTrimChars(input, charsToTrim));

		input = "abcxxxabc";
		charsToTrim = "cab";
		expectedOutput = "xxx";
		assertEquals(expectedOutput, StringUtil.allTrimChars(input, charsToTrim));

		input = null;
		expectedOutput = null;
		assertEquals(expectedOutput, StringUtil.allTrimChars(input, charsToTrim));
	}

	@Test
	public void testLTrimChars()
	{
		String input = "aaaxxxaaa";
		String charsToTrim = "a";
		String expectedOutput = "xxxaaa";
		assertEquals(expectedOutput, StringUtil.lTrimChars(input, charsToTrim));

		input = "abcxxxaaa";
		charsToTrim = "bca";
		expectedOutput = "xxxaaa";
		assertEquals(expectedOutput, StringUtil.lTrimChars(input, charsToTrim));
	}

	@Test
	public void testLFillCharsTargetLength()
	{
		String input = "";
		char charToFill = 'a';
		String expectedOutput = "aaa";
		assertEquals(
				expectedOutput,
//				StringUtils.leftPad(input, expectedOutput.length(), charToFill));
				StringUtil.lFillCharsTargetLength(
						input, charToFill, expectedOutput.length()));

		input = "x";
		expectedOutput = "aaax";
		assertEquals(
				expectedOutput,
//				StringUtils.leftPad(input, expectedOutput.length(), charToFill));
				StringUtil.lFillCharsTargetLength(
						input, charToFill, expectedOutput.length()));
	}

	@Test
	public void testRFillCharsTargetLength()
	{
		String input = "";
		char charToFill = 'a';
		String expectedOutput = "aaa";
		assertEquals(
				expectedOutput,
//				StringUtils.rightPad(input, expectedOutput.length(), charToFill));
				StringUtil.rFillCharsTargetLength(
						input, charToFill, expectedOutput.length()));

		input = "x";
		expectedOutput = "xaaa";
		assertEquals(
				expectedOutput,
//				StringUtils.rightPad(input, expectedOutput.length(), charToFill));
				StringUtil.rFillCharsTargetLength(
						input, charToFill, expectedOutput.length()));
	}
}